package com.mz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mz.common.dto.PaginationVo;
import com.mz.common.dto.R;
import com.mz.common.utils.PageDataHandlerUtils;
import com.mz.entity.UmsPermissionInfo;
import com.mz.entity.UmsRoleInfo;
import com.mz.entity.UmsRolePermission;
import com.mz.entity.vo.RoleVo;
import com.mz.entity.vo.UmsRoleInfoQuery;
import com.mz.service.UmsRoleInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (UmsRoleInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:38:36
 */
@RestController
@RequestMapping("/umsRoleInfo")
public class UmsRoleInfoController  {
    /**
     * 服务对象
     */
    @Resource
    private UmsRoleInfoService umsRoleInfoService;

    /**
     * 分页查询所有数据
     *
     * @param page        分页对象
     * @param umsRoleInfo 查询实体
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getRolePagination(PaginationVo paginationVo, UmsRoleInfoQuery umsRoleInfoQuery) throws Exception {

        IPage page = umsRoleInfoService.getRoleList(paginationVo, umsRoleInfoQuery);
        return PageDataHandlerUtils.toR(page);
    }

    @GetMapping("/allList")
    public R getRoleAllListNotPermission(  ) throws Exception {

        List<UmsRoleInfo> roleList = umsRoleInfoService.getRoleAllListNotPermission();
        return R.ok( roleList );
    }

    /**
     * 获取角色对应的权限列表
     * */
    @GetMapping("/permissions")
    public R getRolePermissionList( Long roleId ) throws Exception {

        List<UmsRolePermission> permissionInfos = umsRoleInfoService.getRolePermissionList(roleId);
        return R.ok(permissionInfos);
    }

    /**
     * 新增数据
     *
     * @return 新增结果
     */
    @PostMapping
    public R addRole(@RequestBody @Valid RoleVo roleVo ) throws Exception {

        umsRoleInfoService.addRole( roleVo );
        return R.ok();
    }

    /**
     * 修改数据
     * @return 修改结果
     */
    @PutMapping
    public R updateRole(@RequestBody @Valid RoleVo roleVo ) throws Exception {

        umsRoleInfoService.updateRole( roleVo );
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/remove")
    public R removeRole(@RequestBody List<Long> idList)  throws Exception {

        umsRoleInfoService.removeRole(idList);
        return  R.ok();
    }
}

